package com.attendance.model.Result;

import com.attendance.model.Employee;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * Created by inuyasha on 2016/12/14.
 */
public class CustUserDetails implements UserDetails{

    private static final long serialVersionUID = -1922135614793714181L;

    private Employee employee;

    public CustUserDetails(){
        this.employee = new Employee();
    }

    public CustUserDetails(Employee e){
        if (e == null)
            return;
        this.employee = new Employee();
        this.employee.setUsername(e.getUsername());
        this.employee.setPassword(e.getPassword());
        this.employee.setJob(e.getJob());
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return AuthorityUtils.commaSeparatedStringToAuthorityList(this.employee.getJob().toString());
    }
    @Override
    public String getPassword() {
        return this.employee.getPassword();
    }
    @Override
    public String getUsername() {
        return this.employee.getUsername();
    }
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
    @Override
    public boolean isEnabled() {
        return true;
    }
}